package cn.xorange.commons.file.configuration;

import com.qiniu.storage.BucketManager;
import com.qiniu.storage.Region;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author : yangjian
 * @date : 2022/1/5
 * @description :
 */
@Configuration
//@ConditionalOnProperty(name = "oss.qiniu.enable",havingValue = "true")
public class QiNiuConfig {

    @Resource
    FileConfig fileConfig;

    /**
     * /**
     * * 构造一个带指定Region对象的配置类
     */
    @Bean
    public com.qiniu.storage.Configuration qiNiuConfig() {
        return new com.qiniu.storage.Configuration(Region.huadongZheJiang2());
    }

    /**
     * 认证信息实例
     */
    @Bean
    public Auth auth() {
        return Auth.create(this.fileConfig.qiniuProperties().getAccessKey(), this.fileConfig.qiniuProperties().getSecretKey());
    }
    /**
     * 构建一个七牛上传工具实例
     */
    @Bean
    public UploadManager uploadManager() {
        return new UploadManager(qiNiuConfig());
    }

    /**
     * 构建七牛空间管理实例
     */
    @Bean
    public BucketManager bucketManager() {
        return new BucketManager(auth(), qiNiuConfig());
    }


}
